#include "common.h"

S_TIMESTRU GetTime(){

    S_TIMESTRU s_time;

    time_t time1;

    struct tm * when;

    time(&time1);

    when = localtime(&time1);

    s_time.nYear = when -> tm_year + 1900;

    s_time.nMon = when -> tm_mon + 1;

    s_time.nDay = when -> tm_mday;

    s_time.nHour = when -> tm_hour;

    s_time.nMin = when -> tm_min;

    s_time.nSec = when -> tm_sec;

    return s_time;
}

S_TIMESTRU GetOffsetTime(S_TIMESTRU timestru, int nOffsetSec)
{
	S_TIMESTRU timestruAfter;
	time_t ttime;
	struct tm when;

	memset(&when, 0, sizeof(when));
	when.tm_year = timestru.nYear - 1900;
	when.tm_mon  = timestru.nMon - 1;
	when.tm_mday = timestru.nDay;
	when.tm_hour = timestru.nHour;
	when.tm_min  = timestru.nMin;
	when.tm_sec  = timestru.nSec;

	ttime = mktime(&when) + nOffsetSec;

	when = *localtime(&ttime);

	timestruAfter.nYear = when.tm_year + 1900;
	timestruAfter.nMon = when.tm_mon + 1;
	timestruAfter.nDay = when.tm_mday;
	timestruAfter.nHour = when.tm_hour;
	timestruAfter.nMin = when.tm_min;
	timestruAfter.nSec = when.tm_sec;

	return timestruAfter;
}
